import datetime
import time

DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
TIME_FORMAT = "%H:%M:%S"


# 当前毫秒数
def cur_millisecond():
    return int(time.time() * 1000)


# 当前秒数
def cur_second():
    return int(time.time())


# 当前日期 格式%Y-%m-%d %H:%M:%S
def cur_datetime():
    return datetime.datetime.strftime(datetime.datetime.now(), DATETIME_FORMAT)

# 当前日期 格式%Y-%m-%d
def cur_date():
    return datetime.date.today()


# 当前时间 格式%Y-%m-%d
def cur_time():
    return time.strftime(TIME_FORMAT)

# 秒转日期
def second_to_datetime(seconds):
    return time.strftime(DATETIME_FORMAT, time.localtime(seconds))


# 毫秒转日期
def millisecond_to_datetime(milli_second):
    return time.strftime(DATETIME_FORMAT, time.localtime(milli_second // 1000))


# 日期转毫秒
def datetime_to_millisecond(dates_time):
    data = time.strptime(dates_time, DATETIME_FORMAT)
    return int(time.mktime(data)) * 1000


# 日期转秒
def datetime_to_second(dates_time):
    data = time.strptime(dates_time, DATETIME_FORMAT)
    return int(time.mktime(data))


# 当前年
def cur_year():
    return datetime.datetime.now().year


# 当前月
def cur_month():
    return datetime.datetime.now().month


# 当前日
def cur_day():
    return datetime.datetime.now().day


# 当前时
def cur_hour():
    return datetime.datetime.now().hour


# 当前分
def cur_minute():
    return datetime.datetime.now().minute


# 当前秒
def cur_seconds():
    return datetime.datetime.now().second


# 星期几
def cur_week():
    return datetime.datetime.now().weekday()


# 几天前的时间
def now_days_ago(days):
    days_ago_time = datetime.datetime.now() - datetime.timedelta(days=days)
    return time.strftime(DATETIME_FORMAT, days_ago_time.timetuple())


# 几天后的时间
def now_days_after(days):
    days_after_time = datetime.datetime.now() + datetime.timedelta(days=days)
    return time.strftime(DATETIME_FORMAT, days_after_time.timetuple())


# 某个日期几天前的时间
def date_time_days_ago(dates_time, days):
    data_time_ago = datetime.datetime.strptime(dates_time, DATETIME_FORMAT) - datetime.timedelta(days=days)
    return time.strftime(DATETIME_FORMAT, data_time_ago.timetuple())


# 某个日期几天前的时间
def date_time_days_after(dates_time, days):
    data_time_after = datetime.datetime.strptime(dates_time, DATETIME_FORMAT) + datetime.timedelta(days=days)
    return time.strftime(DATETIME_FORMAT, data_time_after.timetuple())